package leetcode;

import java.util.*;

/**
 * ClassName: XiechengT4
 * Package: leetcode
 * Description:
 *
 * @Author wjn
 * @Create 2025/9/6 15:01
 * @Version 1.0
 */
public class XiechengT4 {
    static int n, m;
    static boolean[] isRed;
    static List<List<int[]>> graph;
    static int[] redPoints;
    static long[] distU, distV;
    static int u, v;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        isRed = new boolean[n + 1];
        redPoints = new int[m];
        for (int i = 0; i < m; i++) {
            redPoints[i] = scanner.nextInt();
            isRed[redPoints[i]] = true;
        }
        graph = new ArrayList<>();
        for (int i = 0; i <= n; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            int u = scanner.nextInt();
            int v = scanner.nextInt();
            int w = scanner.nextInt();
            graph.get(u).add(new int[]{v, w});
            graph.get(v).add(new int[]{u, w});
        }

        int start = redPoints[0];
        long[] distStart = bfs(start);
        u = start;
        long maxDist = 0;
        for (int i = 1; i <= n; i++) {
            if (isRed[i] && distStart[i] > maxDist) {
                maxDist = distStart[i];
                u = i;
            }
        }

        distU = bfs(u);
        v = u;
        maxDist = 0;
        for (int i = 1; i <= n; i++) {
            if (isRed[i] && distU[i] > maxDist) {
                maxDist = distU[i];
                v = i;
            }
        }

        distV = bfs(v);

        long low = 0, high = distU[v];
        while (low <= high) {
            long mid = low + (high - low) / 2;
            if (check(mid)) {
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        System.out.println(low);
    }

    static long[] bfs(int start) {
        long[] dist = new long[n + 1];
        Arrays.fill(dist, -1);
        Queue<Integer> queue = new LinkedList<>();
        dist[start] = 0;
        queue.offer(start);
        while (!queue.isEmpty()) {
            int node = queue.poll();
            for (int[] neighbor : graph.get(node)) {
                int next = neighbor[0];
                int weight = neighbor[1];
                if (dist[next] == -1) {
                    dist[next] = dist[node] + weight;
                    queue.offer(next);
                }
            }
        }
        return dist;
    }

    static boolean check(long D) {
        List<Integer> A = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            if (isRed[i] && distU[i] > D && distV[i] > D) {
                A.add(i);
            }
        }
        if (A.isEmpty()) {
            return true;
        }
        if (D == 0) {
            return false;
        }
        int s = A.get(0);
        long[] distS = bfs(s);
        long maxDist = -1;
        int x = s;
        for (int node : A) {
            if (distS[node] > maxDist) {
                maxDist = distS[node];
                x = node;
            }
        }
        long[] distX = bfs(x);
        maxDist = -1;
        for (int node : A) {
            if (distX[node] > maxDist) {
                maxDist = distX[node];
            }
        }
        return maxDist <= 2 * D;
    }
}
